package com.cdm.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.cdm.pojo.tDomain;
import com.cdm.service.DomainService;

@Controller
@RequestMapping("/domain")
public class DomainController {
	
	@Autowired
	private DomainService domainService;
	
	@Autowired
	private HttpServletRequest request;
	
	@RequestMapping("/getDomain")
	public void getDomain(HttpServletResponse response) throws Exception{
		Map<String, Object> map=new HashMap<String, Object>();
		String namespace  = request.getParameter("namespace");
		Integer parentId = Integer.parseInt(request.getParameter("parentId"));
 		map.put("namespace",namespace);
 		map.put("parentId", parentId);
		List<tDomain> domains = domainService.getDomain(map);
		//Integer infoSum = domainService.findActivityCount(map);
		JSONObject jsonObject=new JSONObject();
		if (domains!=null && domains.size()>0) {
			jsonObject.put("result", "sucess");
		}else{
			jsonObject.put("result", "false");
		}
		jsonObject.put("namespace", namespace);
		jsonObject.put("parentId", parentId);
		/*jsonObject.put("infoSum", infoSum);
		jsonObject.put("pageSum", infoSum % pageSize == 0 ? infoSum/pageSize :infoSum/pageSize + 1);*/
		jsonObject.put("domains", domains);
		PrintWriter write = response.getWriter();
		write.println(jsonObject);
		write.flush();
		write.close();
	}
}
